<template>
  <div>
    <div class="userContent">
      <el-row>
        <el-col :span="12">
          <el-form ref="form" :model="form" label-width="100px">
            <el-form-item prop="title" label="标题">
              <el-input v-model="form.title" disabled></el-input>
            </el-form-item>
            <el-form-item prop="tag_id" label="任务类别">
              <el-input v-model="form.tag_id" disabled></el-input>
            </el-form-item>
            <el-form-item prop="date" label="发布日期">
              <el-input v-model="form.date" disabled></el-input>
            </el-form-item>
            <el-form-item prop="content" label="任务内容">
              <el-input type="textarea" :autosize="{minRows:1,maxRows:50}" v-model="form.content" disabled></el-input>
            </el-form-item>
            <el-form-item prop="publisherName" label="发布者">
              <el-input v-model="form.publisherName" disabled></el-input>
            </el-form-item>
            <el-form-item prop="reward" label="酬金">
              <el-input v-model="form.reward" disabled></el-input>
            </el-form-item>
            <el-form-item prop="phone" label="电话号码">
              <el-input v-model="form.phone" disabled></el-input>
            </el-form-item>
          </el-form>
          <el-button type="primary" @click="Finish">任务完成</el-button>
        </el-col>
      </el-row><br>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
import router from '../../router'
export default {
  name: `ReadTaskInExecution`,
  data () {
    return {
      id: this.$route.params.id,
      form: {}
    }
  },
  methods: {
    Finish () {
      this.$axios({
        url: `user/task/finish`,
        method: 'post',
        data: {
          id: this.id.toString()
        }
      }).then(res => {
        if (res.data.status === 100) {
          console.log(this.id)
          alert('操作成功')
        } else {
          alert('操作失败')
        }
      }).catch(err => {
        alert(err)
        router.replace('/login')
      })
    },
    getTaskData (id) {
      if (id === null) {
        return this.$router.push({
          path: '/TaskInProgress'
        })
      } else {
        axios.get(`user/task/tasks/inExecution`, {
          params: {
            id: this.id
          }
        }).then(res => {
          if (res.data.status === 100) {
            this.form = res.data.data
          } else {
            alert('获取失败')
          }
        }).catch(err => {
          alert(err)
          router.replace('/login')
        })
      }
    }
  },
  created () {
    this.getTaskData(this.$route.params.id)
  }
}
</script>

<style scoped>

</style>
